var ns, toast;
var app = new Vue({
    el: '#app',
    data: {
        ID:0,
        Name:'',
        Type:1,
        Summary:'',
        CardBgActive:1,
        bglist:[
            {
                id:1,
                bgurl:'http://192.168.0.50:8090/styles/images/shoppingmall/couponbg1.png',
            },
            {
                id:2,
                bgurl:'http://192.168.0.50:8090/styles/images/shoppingmall/couponbg2.png',
            },
            {
                id:3,
                bgurl:'http://192.168.0.50:8090/styles/images/shoppingmall/couponbg3.jpg',
            }
        ],
        businessImg:'',
        businessName:'',
    },
    methods: {
        //获取商家信息
        get_business:function(){
            var that=this;
            ns.post({
                action: 'getbusinessdetail',
            }, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.businessImg=data.data.CoverImage;
                        that.businessName=data.data.BusinessName;
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_select_type:function(type){
            var that=this;
            that.Type=type;
        },

        checkbg:function(id){
            var that=this;
            that.CardBgActive=id;
        },
        do_savecard:function(){
            var that = this;
            if(!that.Name){
                return api.toast({
                    msg: '请填写会员卡名称',
                    duration: 2000,
                    location: 'bottom'
                });
            }
            var cardid=0;
            if(that.ID>0){
                cardid=that.ID
            }else{
                cardid=0
            }
            ns.post({
                action: 'savebusinessmembercard',
                ID:cardid,
                Name: that.Name,
                Type: that.Type,
                CardBgActive: that.CardBgActive,
                Summary: that.Summary,
            }, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        api.toast({
                            msg: '会员卡配置成功',
                            duration: 2000,
                            location: 'bottom'
                        });
                        api.sendEvent({
                            name:'load_huiyuan'
                        })
                        setTimeout(() => {
                            api.closeWin()
                        }, 400);
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        }
    },
});

apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.get_business();
    app.ID= api.pageParam.item.ID;
    app.Name= api.pageParam.item.Name;
    app.Type= api.pageParam.item.Type;
    app.CardBgActive= api.pageParam.item.CardBgActive;
    app.Summary= api.pageParam.item.Summary;

}
